import { createStore } from 'vuex'

import {ajax} from '@/api/index';

export default createStore({
  state: {
    userInfo:null,
    roleList:[],
    cateList:[],
    typeList:[],
    flag:false,
  },
  mutations: {
    updUserInfo(state,payload){
      state.userInfo = payload ; 
    },
    updRoleList(state,payload){
      state.roleList = [...payload] ; 
    },
    updCateList(state,payload){
      state.cateList = [...payload] ;
    },
    updTypeList(state,payload){
      state.typeList = [...payload] ;
    },
    updFlag(state,payload){
      state.flag = payload ; 
    }
  },
  actions: {
    async getUserInfo({commit}){
      let {code,data} = await ajax.getUserInfo();
      if(code){
        commit('updUserInfo',data);
      }
    },
    async getCateInfo({commit}){
      let {code,data} = await ajax.getCate();
      if(code == 200){
        commit('updCateList',data);
      }
    },
    async getRoleInfo({commit}){
      let {code,data} = await ajax.getRole();
      if(code == 200){
        commit('updRoleList',data);
      }
    },
    async getTypeInfo({commit}){
      let {code,data} = await ajax.getType();
      if(code == 200){
        commit('updTypeList',data);
      }
    }
  },
  modules: {
  }
})
